<template>
  <div class="pageItem_warp">
    <div class="header_warp">
      <img class="header_typeIcon" @click="openTypeBtn" src="../assets/ic_type.png" alt />
      <img class="header_storeIcon" src="../assets/LOGO@3x.png" alt />
      <div class="phone_warp" @click="goBack">
        <div v-if="userInfo">{{userInfo.mobile}}</div>
        <img class="ic_downFFF" src="../assets/ic_dowm.png" alt />
        <img class="ic_down333" src="../assets/xial.png" alt />
      </div>
      <div v-if="isBack" class="back" @click="goRegister">退出</div>
    </div>
  <!-- 轮播图 -->
    <div class="swiper">
      <swipe :autoplay="5000" indicator-color="#fff">
        <swipe-item v-for="(image, index) in SwiperImg" @click="goDetails(image.url)" :key="index">
          <img :src="image.image" />
        </swipe-item>
      </swipe>
  <!-- 搜索框 -->
      <div class="swiper_input">
        <img v-if="iconSearch" src="../assets/ic_search.png" class="swiper_icon" alt />
        <input
          type="text"
          @blur="searchProject"
          @focus="focu_search"
          v-model="searchInp"
          placeholder="搜索项目"
        />
      </div>
    </div>
    <div style="position:relative;" class="type750">
      <div class="indexType_warp">
        <div
          v-for="(item,index) in typeList"
          @click="chooseType(index,item.id)"
          :class="typeCss==index?'typeCss':''"
          :key="index"
        >{{item.name}}</div>
        <div class="search750_warp">
          <input type="text" @blur="searchProject" v-model="searchInp" placeholder="搜索项目" />
          <img src="../assets/ic_search.png" alt />
        </div>
      </div>
    </div>
    <goods-list v-if="goodsList" :goodsList="goodsList"></goods-list>

    <div class="footer" v-if="footerInfo">
      <div class="footer_phone">
        <div class="footer_phone_item">
          <img class="qq" src="../assets/ic_qq.png" alt />
          <div>
            <div>企业QQ：</div>
            <div>{{footerInfo.qq_company}}</div>
          </div>
        </div>
        <div class="footer_phone_item">
          <img class="qq" src="../assets/ic_phone.png" alt />
          <div>
            <div>合作电话：</div>
            <div>{{footerInfo.mobile_company}}</div>
          </div>
        </div>
        <div class="footer_phone_item">
          <img class="qq" src="../assets/ic_tel.png" alt />
          <div>
            <div>客服热线：</div>
            <div>{{footerInfo.online_company}}</div>
          </div>
        </div>
      </div>
      <div class="footer_content">
        <div>
          <div>全年服务热线： {{footerInfo.online_company}}</div>
          <div>E-mail：{{footerInfo.email_company}}</div>
          <div>公司地址：{{footerInfo.address_companey}}</div>
        </div>
        <img :src="'http://case.xzkj518.com'+footerInfo.wechat_company" alt />
      </div>
      <div class="guanzhu">关注我们</div>
      <div class="footer_footter">
        <div>{{footerInfo.comtent_company}}</div>
        <div>{{footerInfo.beian}}</div>
      </div>
    </div>
    <div class="mask" v-if="isMask"></div>
    <popup style="margin-top:35px;" v-model="isMask" position="top">
      <div class="popup_warp">
        <div class="popup_box">
          <div
            v-for="(item,index) in typeList"
            @click="chooseType(index,item.id)"
            :class="typeCss==index?'typeCss2':''"
            :key="index"
          >{{item.name}}</div>
        </div>
      </div>
    </popup>
  </div>
</template>
<script >
import { Popup, Popover } from "vux";
import { NavBar, Swipe, SwipeItem } from "vant";
import swiperText from "@/components/swiperText";
import * as API from "@/http/common/api";
import goodsList from "@/components/goodsList";
import { mapState, mapMutations, mapGetters, mapActions } from "vuex";

export default {
  name: "index",
  data() {
    return {
      isBack: false,
      searchInp: "", //搜索输入框
      footerInfo: null, //
      projectList: null,
      typeList: null,
      typeCss: 0,
      SwiperImg: [],
      goodsList: [],
      userInfo: null,
      isMask: false,
      iconSearch: true
    };
  },
  methods: {
    focu_search() {
      this.iconSearch = false;
    },
    goBack() {
      this.isBack = !this.isBack;
    },
    //去注册
    goRegister() {
      this.$router.push({ path: "/register" });
    },
    //去详情
    goDetails(item) {
      console.log(item);
      window.location.href = item;
    },
    //类型选择
    chooseType(e, id) {
      this.typeCss = e;
      this.typeId = id;
      this.$store.dispatch("locTypeId", id);
      this.isMask=false;
     
    },
    //左上角 打开类型弹窗
    openTypeBtn() {
      this.isMask = !this.isMask;
    },
    //搜索
    searchProject() {
      // if(this.searchInp){
      this.iconSearch = true;
      this.ProjectList();
      // }
    },
    // 项目列表
    ProjectList() {
      this.$http(API.ProjectList, {
        type: "GET",
        params: {
          page: this.pageNum,
          page_size: 1500,
          category_id: this.$store.state.typeId, //分类id
          search: this.searchInp //搜索内容
        }
      }).then(res => {
         this.goodsList = res.data.data.list;
      });
    },
    // footer信息
    websmsconf() {
      this.$http(API.websmsconf, {
        type: "GET",
        params: {
          // page: this.pageNum,
          // page_size: 1500,
          // category_id: this.$store.state.typeId, //分类id
          // search: this.searchInp //搜索内容
        }
      }).then(res => {
        this.footerInfo = res.data.data;
      });
    },
    // 轮播图
    bannerList() {
      this.$http(API.bannerList, {
        type: "GET",
        params: {}
      }).then(res => {
        this.SwiperImg = res.data.data;
      });
    },
    // 分类
    CategoryList() {
      this.$http(API.CategoryList, {
        type: "GET",
        params: {}
      }).then(res => {
        this.$localStorage.set("typeList", JSON.stringify(res.data.data));
        console.log("哈哈哈哈",res)
        this.typeList = res.data.data;
      });
    }
  },
  computed: {
    // ...mapState({
    //   typeId: state => state.typeId
    // })
    typeId: {
      get() {
        return this.$store.state.typeId;
      },
      set(val) {}
    }
  },
  watch: {
    searchInp(newVal, oldVal) {
      if (newVal) {
        this.hasSearch = true;
        this.queryByConditions();
      } else {
        this.hasSearch = false;
      }
    },
    typeId(newVal, oldVal) {
      this.ProjectList();
    }
  },
  mounted() {
    if (!JSON.parse(this.$localStorage.get("userInfo"))) {
      this.$router.push({ path: "/register" });
    } else {
      this.userInfo = JSON.parse(this.$localStorage.get("userInfo"));
    }

    // if(!JSON.parse(this.$localStorage.get( "typeList" ))){
    this.CategoryList(); //分类
    // }
    this.ProjectList(); //商品列表
    this.websmsconf(); //底部信息
    this.bannerList(); //轮播图
  },
  components: {
    Popup,
    Swipe,
    SwipeItem,
    swiperText,
    goodsList,
    Popover
  }
};
</script>
<style scoped lang='less'>
.header_warp {
  display: flex;
  position: absolute;
  width: 100%;
  height: 70px;
  justify-content: space-between;
  align-items: center;
  box-sizing: border-box;
  padding: 0 20px;
  background: rgba(0, 0, 0, 0);
  color: #fff;
  z-index: 999999999;
  img {
    width: 46px;
    height: 40px;
  }
}
.swiper {
  width: 100%;
  position: relative;
  .van-swipe {
  }
  img {
    width: 100%;
    height: 100%;
    pointer-events: none;
  }
}

.van-swipe-item {
}
.indexType_warp {
  display: flex;
  flex-wrap: wrap;
  width: 100%;
  justify-content: center;
  align-items: center;
  font-size: 24px;
  height: 77px;
  font-size: 24px;
  background: #fff;
  div {
    height: 76px;
    line-height: 76px;
    text-align: center;
    margin: 0 30px;
  }
}
.search750_warp {
  // position: absolute;
  // top: 20px;
  // right: 80px;
  border-radius: 30px;
  border: 2px solid #999;
  height: 35px !important;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px 0 20px;
  width: 300px;
  input {
    height: 35px !important;
    font-size: 20px !important;
  }
  img {
    width: 22px;
    height: 22px;
  }
}
.popup_box {
  background: #fff;
  display: flex;
  // padding-top:81px;
  flex-wrap: wrap;
  padding: 20px 0 20px 20px;
  box-sizing: border-box;
  div {
    width: 132px;
    height: 56px;
    margin: 10px 20px;
    line-height: 56px;
    font-size: 28px;
    border-radius: 4px;
    text-align: center;
    box-sizing: border-box;
    border: solid 2px #999;
    color: #999;
  }
}
.mask {
  position: fixed;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  z-index: 99;
  left: 0;
  top: 0;
}
.swiper_icon {
  position: absolute;
  left: 120px;
  bottom: 12px;
  width: 26px !important;
  height: 26px !important;
}
.swiper_input {
  position: absolute;
  left: 176px;
  bottom: 20px;
  input {
    width: 400px;
    height: 50px;
    text-align: center;
    border-radius: 50px;
  }
}
.typeCss {
  color: #0076fe;
  border-bottom: #0076fe 3px solid;
}
.phone_warp {
  display: flex;
  align-items: center;
  img {
    width: 20px;
    height: 20px;
    margin-top: 5px;
    margin-left: 10px;
  }
}
.back {
  position: absolute;
  width: 60px;
  height: 30px;
  color: #999;
  background: #fff;
  right: 00px;
  top: 60px;
  text-align: center;
  line-height: 30px;
  border-radius: 4px;
  border: 2px solid #eee;
}
.header_storeIcon {
  width: 156px !important;
  height: 40px !important;
  margin-left: 20px;
}
.typeCss2 {
  border: #0076fe 2px solid !important;
  color: #0076fe !important;
}
.footer {
  background: #242424;
  color: #fff;
  box-sizing: border-box;
  padding-top: 66px;
  .footer_phone {
    font-size: 18px;

    display: flex;
    align-items: center;
    justify-content: center;
    width: 70%;
    margin: 0 auto;
    box-sizing: border-box;
    justify-content: space-between;
    .footer_phone_item {
      display: flex;

      align-items: center;
      img {
        width: 72px;
        height: 72px;
        margin-right: 26px;
      }
    }
  }
  .footer_content {
    width: 70%;
    margin: 0 auto;
    display: flex;
    box-sizing: border-box;
    align-items: center;
    justify-content: space-between;
    margin-top: 45px;
    div {
      div {
        line-height: 40px;
      }
    }
    img {
      width: 146px;
      height: 146px;
    }
  }
  .guanzhu {
    text-align: right;
    width: 70%;
    margin: 0 auto;
    box-sizing: border-box;
    margin-top: 10px;
    margin-bottom: 25px;
    padding-right: 40px;
  }
  .footer_footter {
    display: flex;
    box-sizing: border-box;
    justify-content: center;
    border-top: #666 solid 2px;
    padding-top: 40px;
    padding-bottom: 40px;
    div {
      margin: 0 20px;
      text-align: center;
    }
  }
}
</style>
